# -*- coding:utf-8 -*-

from . import project
from flask import render_template,session
from admin_model import List_,Code
from project_zczh.tool.common import login_check
import datetime
from project_zczh import redis_store

@project.route('/more/<int:id_>')
@login_check
def more(id_):
    now = datetime.datetime.now()
    from config import timedelta
    timedelta = datetime.timedelta(timedelta)
    check_time = (now - timedelta).strftime("%Y-%m-%d")
    content_list=List_.query.filter_by(code_id=int(id_),mark=1).filter(List_.update_time>check_time).order_by(List_.update_time.desc()).all()
    code=Code.query.filter_by(id=int(id_) ).all()[0]

    user_id = session.get('user_id')
    titles_id = redis_store.lrange(user_id, 0, -1)
    titles_id = ','.join(titles_id)
    if content_list == []:
        return  render_template('404.html')
    if len(content_list) >=10:
        content_list=content_list[:10]
        return render_template('list.html', content_list=content_list,code=code,titles_id=titles_id)
    else:
        return render_template('list.html',content_list=content_list,code=code,titles_id=titles_id)